package com.petshop.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.common.constant.BalzLogger;
import com.common.jdbc.JDBCConnection;
import com.petshop.model.Product;
import com.petshop.model.Shop;


public class ShopDaoImpl extends JDBCConnection implements ShopDao{
	
	BalzLogger logger = new BalzLogger();
	
	private static final String SQL_GET_SHOP = " SELECT * FROM petshop.ps_shop " ;


	public Shop getShopDetail() {
		
		ResultSet rs = queryBySql(SQL_GET_SHOP);
		List<Shop> sList = new ArrayList<Shop>();
		
		try {
			while (rs.next()) {
				sList.add(mapRow(rs));
			}
			rs.close();
		} catch (SQLException e) {
	    	logger.debug("SQLException: " + e.getMessage());
	    }
		
		if (logger.isDebugEnabled()) {
			logger.debug("sql: " + SQL_GET_SHOP);
			logger.debug("result.size(): " + sList.size());
			logger.debug("result>> " + sList);
		}

		Shop shop = new Shop();
		
		if(sList.size()>0){
			shop = sList.get(0);
		}
		
		return shop;
	}
	
	
	// ---------------------------------------------------------------------------------------------------- RowMapper
	public Shop mapRow(ResultSet rs) throws SQLException {
		
		Shop model = new Shop();
		
		model.setPs_promotion(rs.getString("ps_promotion"));
		model.setPs_about_us(rs.getString("ps_about_us"));
		model.setPs_about_shop(rs.getString("ps_about_shop"));
		model.setPs_contact_us(rs.getString("ps_contact_us"));
		
		return model;
	}
	
	
}
